import 'package:flutter/material.dart';
import 'package:flutter_swipe_action_cell/core/cell.dart';
import 'package:get/get.dart';
import 'package:get/get_connect/http/src/utils/utils.dart';
import 'package:industry_net/base/common/util.dart';
import '../controller.dart';
import '../../models/msg.dart';

class MsgCell extends StatelessWidget {
  MsgCell({
    Key? key,
    required this.md,
  }) : super(key: key);
  final MsgModel md;
  final controller = Get.find<MsgController>();
  final GlobalKey _key = GlobalKey();
  @override
  Widget build(BuildContext context) {
    double _size = 45.r;
    return SwipeActionCell(
      key: _key,
      fullSwipeFactor: 1,
      backgroundColor: ColorsUtil.white,
      child: InkWell(
        onTap: () => controller.actionCellClick(md),
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: gap12, vertical: gap15),
          child: Row(
            children: [
              Container(
                padding: EdgeInsets.all(6.r),
                width: _size,
                height: _size,
                child: loadAvater(
                    url: 'menu_icon_pear.png'.imgPathHome,
                    size: _size - 12.r,
                    fit: BoxFit.contain),
              ),
              SizedBox(
                width: gap10,
              ),
              Expanded(
                child: SizedBox(
                  height: _size,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Text(
                                '交易物流',
                                style: pfSCStyle(
                                    color: ColorsUtil.title, fontSize: font15),
                              ),
                              SizedBox(
                                width: 10.r,
                              ),
                              Text(
                                md.isTop ? '置顶' : '',
                                style: pfMediumStyle(
                                    color: ColorsUtil.red, fontSize: font12),
                              ),
                            ],
                          ),
                          Text(
                            '2021/12.20',
                            style: pfMediumStyle(
                                color: ColorsUtil.content, fontSize: font13),
                          )
                        ],
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Flexible(
                            child: Text(
                              '有超时订单未支付，已被取消，这一行有点长，还挺长',
                              overflow: TextOverflow.ellipsis,
                              maxLines: 1,
                              style: pfMediumStyle(
                                  color: ColorsUtil.subTitle, fontSize: font14),
                            ),
                          ),
                          Container(
                            decoration: BoxDecoration(
                                color: md.isRead ? null : ColorsUtil.red,
                                borderRadius: BorderRadius.circular(2.5.r)),
                            width: 5.r,
                            height: 5.r,
                          ),
                        ],
                      )
                    ],
                  ),
                ),
              )
            ],
          ),
        ),
      ),
      trailingActions: [
        SwipeAction(
          ///
          ///This attr should be passed to first action
          ///
          nestedAction: SwipeNestedAction(title: "确认删除"),
          title: "删除",
          onTap: (CompletionHandler handler) async {
            await handler(true);
            controller.actionDel(md);
          },
          widthSpace: 75.r,
          style: pfMediumStyle(color: ColorsUtil.white, fontSize: font13),
          color: ColorsUtil.red,
        ),
        SwipeAction(
          title: "置顶",
          onTap: (CompletionHandler handler) async {
            ///false means that you just do nothing,it will close
            /// action buttons by default
            handler(false);
            controller.actionTop(md);
          },
          widthSpace: 75.r,
          style: pfMediumStyle(color: ColorsUtil.white, fontSize: font13),
          color: const Color(0xff889099),
        ),
        SwipeAction(
          title: "标记已读",
          onTap: (CompletionHandler handler) async {
            ///false means that you just do nothing,it will close
            /// action buttons by default
            handler(false);
            controller.actionRead(md);
          },
          widthSpace: 75.r,
          style: pfMediumStyle(color: ColorsUtil.white, fontSize: font13),
          color: const Color(0xff257AE3),
        ),
      ],
    );
  }
}
